﻿using NAnt.SVN.Tasks.Constants;
using NAnt.Core.Attributes;
using NAnt.SVN.Attributes;

namespace NAnt.SVN.Tasks
{
    /// <summary>
    /// Superclass of the propset command to set keywords on files
    /// You can run this tasc with the svnkeywords tag in NAnt.
    /// $Id$
    /// </summary>
    [TaskName("svnkeywords")]
    public sealed class Keywords : PropSet
    {
        #region Private Fields

        private string value = string.Empty;

        #endregion

        /// <summary>
        /// The property is fixed here: keywords
        /// </summary>
        public override string Property
        {
            get
            {
                return SVNProperties.KEYWORDS;
            }
            
        }

        /// <summary>
        /// The property value
        /// </summary>
        [TaskAttribute("value", Required = false)]
        [KeywordsValidator()]
        public override string Value
        {
            get
            {
                SVNKeywords keywords = new SVNKeywords();
                if (!string.IsNullOrEmpty(value))
                {
                    string[] values = value.Split(',');
                    for (int i = 0; i < values.Length; i++)
                        keywords.CorrectCasing(ref values[i]);
                }
                else
                {
                    return string.Join(",", keywords.AllStaticFields.ToArray());
                }
                return value;
            }
            set
            {
                this.value = value;
            }
        }
    }
}
